<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
		"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>单盘</title>
	
	<link href="static/css/style.css" rel="stylesheet" type="text/css">
	<link href="static/bootstrap.3.3.7/css/bootstrap.min.css" rel="stylesheet" type="text/css">
	<link rel="stylesheet" href="static/bootstrap.3.3.7/datetimepicker/css/datetimepicker.css">
	<script src="https://images.robustcn.com/public/static/module/common/jquery/jquery-2.2.3.min.js"></script>
	
	<script src="static/bootstrap.3.3.7/js/bootstrap.min.js"></script>
 
	<script src="static/js/picker.min.js"></script>
	<script src="static/js/city.js"></script>
	<script src="static/bootstrap.3.3.7/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
</head>
<body>
<div class="container">
	<h2 class="text-center">个人本命星盘</h2>
	<div class="row">
		<div class="col-md-6 col-md-push-3">
			<!-- AREA CHART -->
			<div class="panel panel-primary">
				<div class="panel-heading">
					<h3 class="panel-title">出生信息</h3>
				</div>
				<table class="table table-bordered">
					<tbody>
					
					<tr>
						<th class="text-center">姓名</th>
						<td class="text-center">
							<div class="col-md-6 col-md-push-3">
								<input class="ulr" value="chart/natal"/>
								<textarea class="daima">{"access_token":"988sfaa4af60932c","svg_type":"1","h_sys":"P","ay":"-1","longitude":"116.4224","latitude":"39.934827","birthday":"2000-01-01 00:00:00","tz":"8","planets":[0,1,2,3,4,5,6,7,8,9,"m"],"is_corpus":"1","format":1,"virtual":[10,11],"phase":{"0":7,"60":5,"90":6,"120":6,"180":7},"planet_degree":{"0":1,"1":1,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"m":2.5},"transitday":"2022-08-18 11:34:09","night_middle":"1","tomorrow_type":"1"}</textarea>
								<button type="button" class="shengchang"  >生成</button>
							</div>
						</td>
					</tr>

					</tbody>
				</table>
			</div>
		</div>
	</div>
	<div class="row">
		<div class="col-md-6 col-md-push-3">
			<div class="bs-example" data-example-id="horizontal-dl">

				<dl class="dl-horizontal">
					<dt><h4>星盘模式:</h4></dt>
					<dd>
						<ul class="nav nav-pills">
							<li role="presentation"><a class="switch_web_ixingpan" bigt="web_ixingpan_cn">文字版</a></li>
							<li role="presentation"><a class="switch_web_ixingpan" bigt="web_ixingpan">符号版</a></li>
							<li role="presentation"><a class="switch_web_ixingpan" bigt="web_ixingpan_senior">高级盘</a></li>
						
						</ul>
					</dd>
				</dl>
			</div>
		</div>
	</div>
</div>


<div class='box-svg'>

</div>

<div id="tip_sign_add">

</div>

</body>
</html>
<script>

    $(".form_datetime").datetimepicker({
        format: 'yyyy-mm-dd hh:ii',
        initialDate: new Date(),
    })
    
    var longitude='121.47',latitude='31.23',tz='8.00',name,h_sys,starsCode,birthday,phase={};
    
    var houseData,signData,planetData,svg;

    $(document).ready(function () {
        var ajax_post = {'access_token': '989f888c4283e2cc2d8a5aa4af60932c'};
 
        //星座滑过提示
        $(document).on('mouseenter', '.sign_font', function (e) {
            var sign_id = $(this).attr("serial");
            signInfo=signData[sign_id];
            var sign_html = '';
            var planet_count = 0;
            var sign_planets_html = '';
            if (signInfo['planet_array'] != null) {
                var planet_array = signInfo['planet_array'];
                for (var p in planet_array) {
                    planet_count++;
                    console.log(planet_array[p]);

                    var planet_info = planet_array[p];
          
                    sign_planets_html += '<span class="must_symbo_font planets_' + planet_info['planet_english'] + '">' + planet_info['planet_font'] + '</span>' +
                        '<span>' + planet_info['planet_chinese'] + '</span>' +
                        '<span class="must_symbo_font  sign_' + planet_info['sign_english'] + '">' + planet_info['sign_font'] + '</span>' +
                        '<span>' + planet_info['sign_chinese'] + '</span>' +
                        '<span> ' + planet_info['deg'] + '°' + planet_info['min'] + '′' + planet_info['sec'] + '″</span><br>';
                }
            } else {
                sign_planets_html = '<span class="">无</span>'
            }
            sign_html += '<div class="tip_sign_content">\n' +
                '<span class="must_symbo_font sign_' + signInfo['sign_english'] + '">' + signInfo['sign_font'] + '</span><b>' + signInfo['sign_chinese'] + '</b> - ' + signInfo['sign_attribute'].join("、") + '<br>' +
                '守护星：' + sign_guardian_html(signInfo['sign_guardian']) + '<br>' +
                '星体数：' + planet_count + '<br>' +
                '详情：<br>' + sign_planets_html;
            sign_html += '</div>';

            showXPTip(e.pageY, e.pageX, sign_html);

        });
        $(document).on('mouseleave', '.sign_font', function () {
            $("#tip_sign_add").hide();
        });


        //宫位滑过提示
        $(document).on('mouseenter', '.house_id', function (e) {
            var house_id = $(this).attr("serial");

            var house_info = houseData[house_id];
            var house_html = '';
            var planet_count = 0;
            var house_planets_html = '';


            if (house_info['planet_array']) {
                var planet_array = house_info['planet_array'];
                for (var p in planet_array) {
                    planet_count++;
                    house_planets_html += '<span class="must_symbo_font planets_' + planet_array[p]['planet_english']+ '">' + planet_array[p]['planet_font'] + '</span>' +
                        '<span>' + planet_array[p]['planet_chinese'] + '</span>' +

                        '<span>第' + house_info['house_id'] + '宫</span>' +
                        '<span> ' + planet_array[p]['deg'] + '°' + planet_array[p]['min'] + '′' + planet_array[p]['sec'] + '″</span><br>';

                }
            }else {
                house_planets_html = '<span class="">无</span>'
            }
			
			
			
            house_html += '<div class="tip_sign_content">\n' +
                '<span>第' + house_info['house_id'] + '宫 </span><b>【' + house_info['house_life'] + '】</b><br>' +

                '宫头：<span class="must_symbo_font sign_' + house_info['sign']['planet_english'] + '">' + house_info['sign']['sign_font']+ '</span>' + house_info['sign']['sign_chinese'] +
                '<span> ' + house_info['sign']['deg'] + '°' + house_info['sign']['min'] + '′' + house_info['sign']['sec'] + '″</span><br>' +
                '宫主星：' + sign_guardian_html(house_info['main_planet']) + '<br>' +
                '星体数：' + planet_count + '<br>' +
                '详情：<br>' + house_planets_html;
            house_html += '</div>';
            showXPTip(e.pageY, e.pageX, house_html);
        });
        $(document).on('mouseleave', '.house_id', function () {
            $("#tip_sign_add").hide();
        });

        //行星滑过提示
        $(document).on('mouseenter', '.planet_font,.guardian_font', function (e) {
            var planet_name = $(this).attr("serial");
			
			for (var pp in planetData) {
			  if(planetData[pp]['planet_english']==planet_name){
			    var planet_info = planetData[pp];
			  }
			}
			
            var planet_html = '';

            var planet_planets_html = '';

            if (planet_info == null) {
			console.log(planet_info);

                planet_html = '<span class="">还未选择当前行星</span>';
            } else {
                console.log(planet_info);
                if (planet_info['planet_allow_degree']) {
                    var planet_allow_degree = planet_info['planet_allow_degree'];

                    for (var p in planet_allow_degree) {

                        planet_planets_html += '与<span class="must_symbo_font planets_' + planet_allow_degree[p]['planet_english'] + '">' + planet_allow_degree[p]['planet_font'] + '</span>' +
                            '<span>' + planet_allow_degree[p]['planet_chinese'] + '成</span>' +
                            '<span>' + planet_allow_degree[p]['allow'] + '°</span>' +
                            '<span class="red"> ' + in_out(planet_allow_degree[p]['in_out']) + '</span>' +
                            '<span>（' + planet_allow_degree[p]['deg'] + '°' + planet_allow_degree[p]['min'] + '′' + planet_allow_degree[p]['sec'] + '）</span><br>';

                    }
                } else {
                    planet_planets_html = '<span class="">无</span><br>'
                }

                planet_html += '<div class="tip_sign_content">\n' +
                    '<span class="must_symbo_font planets_' + planet_info['planet_english'] + '">' + planet_info['planet_font'] + '</span><b>' + planet_info['planet_chinese'] + '</b><span class="red">' + retrograde(planet_info['speed']) + '</span><br>' +

                    '落入星座：<span class="must_symbo_font sign_' + planet_info['sign']['sign_english'] + '">' + planet_info['sign']['sign_font'] + '</span>' + planet_info['sign']['sign_chinese'] +
                    '<span> ' + planet_info['sign']['deg'] + '°' + planet_info['sign']['min'] + '′' + planet_info['sign']['sec'] + '″</span><br>' +
                    
					'落入宫位：<span class="house_'+planet_info['house_id']+'">' + planet_info['house_id'] + '</span>宫<span>' + planet_info['house_deg'] + '°' + planet_info['house_min'] + '′' + planet_info['house_sec'] + '″</span><br>' +
                    '相位：(<span class="red">+</span>为入相位，<span>-</span>为出相位，)<br>' +
                    '详情：<br>' + planet_planets_html;

                planet_html += '<span style="color: gray">** 相位后括号内是容许度</span></div>';
            }

            showXPTip(e.pageY, e.pageX, planet_html);
        });
        $(document).on('mouseleave', '.planet_font,.guardian_font', function () {
           $("#tip_sign_add").hide();
        });
        
        //鼠标滑动提示框
        function showXPTip(y, x, txt) {
            var documentHeight = $(document).height();
            var documentWidth = $(document).width();
            $("#tip_sign_add").empty().append(txt);

            var minWidth = $("#tip_sign_add").outerWidth(true);
            var minHeight = $("#tip_sign_add").outerHeight(true);

            var tip_sign_left = 0;
            var tip_sign_top = 0;

            if (documentWidth < (x + minWidth)) {
                tip_sign_left = x - minWidth;
            } else {
                tip_sign_left = x + 15;
            }

            if (minHeight > y) {
                tip_sign_top = 0;
            } else if (documentHeight < (y + minHeight)) {
                tip_sign_top = y - minHeight;
            } else {
                tip_sign_top = y + 15;
            }

            $("#tip_sign_add").css({top: tip_sign_top, left: tip_sign_left}).show();
        }

	    
        //计算出入相位
        function retrograde(number) {
            if (number > 0) {
                return '<span> [顺行] </span>';
            }
            return '<span> [逆行] </span>';
        }

        //计算出入相位
        function in_out(number) {
            if (number > 0) {
                return '+';
            }
            return '-';
        }

        //守护行星html
        function sign_guardian_html(sign_guardian) {
 
            var guardian_html = '';
            for (var g in sign_guardian) {
                guardian_html += '<span class="must_symbo_font planets_' + sign_guardian[g]['planet_english'] + '">' + sign_guardian[g]['planet_font'] + '</span>' +
                    '<span class="">' + sign_guardian[g]['planet_chinese'] + '</span>';
            }
            return guardian_html;
        }
        //请求数据
        function getData(ajax_post) {

			ajax_post=JSON.parse($('.daima').val());
			var ulr=$('.ulr').val();
            $.ajax({
                type: "POST",
                url: window.location.protocol +"//"+window.location.host+"/astrology/"+ulr,
                data: ajax_post,
                success: function (result) {
                    houseData = result.data.house;
                    signData = result.data.sign;
                    planetData = result.data.planet;
                    svg = result.data.svg; 
                    $(".box-svg").empty().append(svg);

					DisplayGrands(planetData)


                },
                error: function (e) {
                    alert('请求异常');
                }
            });

        }


        //关闭窗口获取
        $('.shengchang').on('click', function () {
 

            getData(ajax_post);
        })

		//版本切换
		$(".switch_web_ixingpan").on("click", function () {
			var bigt_name = $(this).attr("bigt");

			if(bigt_name == 'web_ixingpan_senior'){
				ajax_post['svg_type']=0;
				getData(ajax_post);
			}else{
				if(ajax_post['svg_type']==null || ajax_post['svg_type']==0){
					ajax_post['svg_type']=1;
					getData(ajax_post);
				}
			}

			$('.text_font').css("font-family", bigt_name);
			if (bigt_name == 'web_ixingpan') {
				$('.planet_font').css("font-size", 24);
				$('.sign_font').css("font-size", 34);
			} else if(bigt_name == 'web_ixingpan_cn') {
				$('.planet_font').css("font-size", 16);
				$('.sign_font').css("font-size", 28);
			}else {
			}

		});
		/**
		 * acS   一坨
		 * acGT  腰边三角形
		 * acK   风筝形状
		 * acTS  T三角形
		 * acY   等腰三角形
		 * acGC   正方形
		 * acC   梯形
		 * acMR  长方形
		* */

		function DisplayGrands(planetData)
		{
			var planetAspectArray=new Array();
			var aspectO=new Array();
			var acS=new Array();
			var acGT=new Array();
			var acK=new Array();
			var acTS=new Array();
			var acY=new Array();
			var acGC=new Array();
			var acC=new Array();
			var acMR=new Array();
			for(let pp in planetData) {
				let planet_allow_degree=planetData[pp]['planet_allow_degree'];
				(aspectO[pp] || (aspectO[pp] = {'allow':{}}));
				//aspectO[pp]['code_name']=planetData[pp]['code_name'];
				for(let aa in planet_allow_degree) {
					aspectO[pp][planet_allow_degree[aa]['planet_number']]=planet_allow_degree[aa]['allow'];
				}
			}

			for(let i in planetData) {
				for(let j in planetData) {
					if (j != i) {
						for (let k in planetData) {
							if (k != i && k != j) {

								if (i < j && j < k && aspectO[i][j] == 0 && aspectO[i][k] == 0 && aspectO[j][k] == 0) {
									acS.push([i, j, k]);
									/* Is there a Grand Trine? */
								}else if (i < j && j < k && aspectO[i][j] == 120 && aspectO[i][k] == 120 && aspectO[j][k] == 120) {
									/* 计算等腰边三角形 */
									acGT.push([i, j, k]);
									for (let l in planetData) {
										/* 计算风筝 */
										if (aspectO[min(i, l)][max(i, l)] == 60 && aspectO[min(j, l)][max(j, l)] == 60) {
											acK.push([i, j, k, l]);
										}
										if (aspectO[min(j, l)][max(j, l)] == 60 && aspectO[min(k, l)][max(k, l)] == 60) {
											acK.push([i, j, k, l]);
										}
										if (aspectO[min(i, l)][max(i, l)] == 60 && aspectO[min(k, l)][max(k, l)] == 60) {
											acK.push([i, j, k, l]);
										}
									}
								} else if (j < k && aspectO[j][k] == 180 && aspectO[min(i, j)][max(i, j)] == 90 && aspectO[min(i, k)][max(i, k)] == 90) {
									/* 计算T三角形 */
									acTS.push([i, j, k]);
								}else if (j < k && aspectO[j][k] == 60 && aspectO[min(i, j)][max(i, j)] == 150 && aspectO[min(i, k)][max(i, k)] == 150) {
									/* 计算等腰三角形 */
									acY.push([i, j, k]);
								}

								for (let l in planetData) {
									if (i < j && i < k && i < l && j < l && aspectO[i][j] == 90 && aspectO[i][l]  == 90 && aspectO[min(j, k)][max(j, k)] == 90   && aspectO[min(k, l)][max(k, l)] == 90 &&  MinDistance(planetData[i]['longitude'], planetData[k]['longitude'])>150 &&  MinDistance(planetData[j]['longitude'], planetData[l]['longitude'])>150) {
										/* 正方形 */
										acGC.push([i, j, k,l]);
									}
									else if (i < l &&  aspectO[min(i, j)][max(i, j)] == 60 &&  aspectO[min(j, k)][max(j, k)] == 60 &&  aspectO[min(k, l)][max(k, l)] == 60 &&  MinDistance(planetData[i]['longitude'], planetData[l]['longitude'])>150)
									{
										/*梯形 */
										acC.push([i, j, k,l]);
									}
									else if (i < j && i < k && i < l && aspectO[min(i, j)][max(i, j)] == 180 && aspectO[min(k, l)][max(k, l)] == 180 && aspectO[min(i, k)][max(i, k)] == 120 && aspectO[min(j, l)][max(j, l)] == 120)
									{
										/*长方形 */
										acMR.push([i, j, k,l]);
									}
								}

							}
						}
					}
				}
			}
			console.log('acS',acS);
			console.log('acGT',acGT);
			console.log('acK',acK);
			console.log('acTS',acTS);
			console.log('acY',acY);
		}

		function max(i, j) {
			if (i > j) {
				return i;
			} else {
				return j;
			}
		}
		function min(i, j) {
			if (i < j) {
				return i;
			} else {
				return j;
			}
		}
		function  MinDistance(deg1, deg2) {
			var i;
			i = Math.abs(deg1 - deg2);
			return i < 180 ? i : 360 - i;
		}
		 
		
    });
    
</script>



